<template>
  <div class="center">

    <div v-if="scoreVisible">
      <score :studentInfo="studentInfo" @scoreClose="scoreClose"></score>
    </div>

    <div v-else>
      <!-- 头部 -->
      <div class="table_header flex flex_bet flex-wrap">
        <div class="table_button">
          <el-button type="primary" icon="el-icon-refresh" size="mini" @click="Refresh"></el-button>
          <el-button v-permission="['超级管理员', '管理员', '代理商', '学校']" type="primary" icon="el-icon-plus" size="mini" @click="formVisible=true">
            添加学员
          </el-button>
          <el-button  v-permission="['超级管理员', '管理员', '代理商', '学校']" type="primary" size="mini" @click="consumeFormVisible=true">批量导入学员</el-button>
          <el-button v-permission="['超级管理员', '管理员', '代理商', '学校']" type="primary"  size="mini" @click="handelDelete">
            批量删除
          </el-button>
          <el-button v-permission="['超级管理员', '管理员', '代理商', '学校']" type="primary" icon="el-icon-upload2" size="mini" @click="exportFormVisible = true">导出</el-button>
          <el-button v-permission="['超级管理员', '管理员', '代理商', '学校']" type="primary" size="mini" @click="handleDownload">批量导入模板<i class="el-icon-paperclip el-icon--right"></i></el-button>
        </div>
        <div class="table_searchs flex felx_align">
          <div class="table_search flex">
            <el-input placeholder="搜索" v-model="searchTable" class="input-with-select" size="small">
              <el-select v-model="select" slot="prepend" placeholder="请选择" class="table_select" style="width:105px">
                <el-option label="账号" value="1"></el-option>
              </el-select>
              <el-button slot="append" icon="el-icon-search" @click="idnameSearch"></el-button>
            </el-input>
          </div>
          <dynamicTable :checkboxVal="checkboxVal" @alter="alterCheckbok"/>
        </div>
      </div>
      <el-table stripe style="width: 100%" border fit highlight-current-row ref="tableDataRef" :data="tableData" :key="key" @sort-change="tableSortCge" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column v-if="colData[0].istrue" min-width="50" align="center" prop="id" label="ID" fixed></el-table-column>
        <el-table-column v-if="colData[1].istrue" min-width="120" align="center" prop="account" label="账号" fixed></el-table-column>
        <el-table-column v-if="colData[2].istrue" min-width="120" align="center" prop="qid" label="QID" fixed></el-table-column>
        <el-table-column v-if="colData[2].istrue" min-width="80" align="center" prop="uid" label="UID" fixed></el-table-column>
        <el-table-column v-if="colData[3].istrue" min-width="70" align="center" prop="adminName" label="归属" fixed></el-table-column>
        <el-table-column v-if="colData[4].istrue" min-width="50" align="center" prop="username" label="姓名" fixed></el-table-column>
        <el-table-column v-if="colData[5].istrue" min-width="50" align="center" prop="sex" label="性别">
          <template slot-scope="scope">
            <span v-if="scope.row.sex==1">男</span>
            <span v-else>女</span>
          </template>
        </el-table-column>
        <el-table-column v-if="colData[6].istrue" min-width="70" align="center" prop="gradeName" label="年级">
        </el-table-column>
        <el-table-column v-if="colData[7].istrue" min-width="100" align="center" prop="address" label="详细地址"></el-table-column>
        <el-table-column v-if="colData[8].istrue" min-width="70" align="center" prop="school" label="校区"></el-table-column>
        <el-table-column v-if="colData[9].istrue" min-width="100" align="center" prop="teacherName" label="责任教师"></el-table-column>
        <el-table-column v-if="colData[10].istrue" min-width="140" align="center" prop="login_time" label="最后登录日期"></el-table-column>
        <el-table-column v-if="colData[11].istrue" min-width="120" align="center" prop="login_sn" label="最后登录设备SN"></el-table-column>
        <el-table-column v-if="colData[12].istrue" min-width="90" align="center" prop="sup_all_time" label="督学总课时">
        </el-table-column>
        <el-table-column v-if="colData[13].istrue" min-width="90" align="center" prop="sup_residue_time" label="督学余课时">
          <template slot-scope="scope">
            <span>{{scope.row.sup_all_time-scope.row.sup_use_time}}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="colData[14].istrue" min-width="90" align="center" prop="acc_all_time" label="伴学总课时">
        </el-table-column>
        <el-table-column v-if="colData[15].istrue" min-width="100" align="center"  label="伴学余课时">
          <template slot-scope="scope">
            <span>{{scope.row.acc_all_time-scope.row.acc_use_time}}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="colData[16].istrue" min-width="80" align="center" prop="money" label="彩虹币"></el-table-column>
        <el-table-column label="操作" min-width="200" align="center">
          <template slot-scope="scope">
            <el-row>
              <el-button v-permission="['超级管理员', '管理员', '代理商', '学校']" size="mini" type="primary" @click="openEdit(scope.row)">编辑</el-button>
              <el-button v-permission="['超级管理员', '管理员', '代理商', '学校']" size="mini" @click="delContent(scope.row.id)">删除</el-button>
              <el-popover placement="left" width="300" trigger="click">
                <el-button type="text" size="mini" @click="openTask(scope.row.id)">学习任务</el-button>
                <el-button  size="mini" type="text" @click="scoreShow(scope.row)">成绩</el-button>
                <el-button v-permission="['超级管理员', '管理员', '代理商', '学校']" size="mini" type="text" @click="openHourEdit(scope.row)">课时</el-button>
                <el-button size="mini" type="text" @click="openHourLog(scope.row)">课时操作日志</el-button>
                <el-button size="mini" type="text" @click="goToGanKao(scope.row.uid)">学情</el-button>
                <el-button slot="reference" size="mini">更多</el-button>
              </el-popover>
            </el-row>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="paging">
        <el-pagination :current-page.sync="listQuery.startSize" background @size-change="handleSizeChange"
                       @current-change="handleCurrentChange" :page-sizes="[10, 50, 100, 200]"
                       layout="total, sizes, prev, pager, next, jumper" :total="total" :page-size="listQuery.pageSize">
        </el-pagination>
      </div>
      <delete-Dialog title="" :visible.sync="deleteDialogs.show" width="25%" top="40vh" @deleteEvents="deleteEvents" :deleteText="deleteDialogs.deleteText"/>

      <el-dialog :title="editSubjects ? '编辑' : '添加'" :visible.sync="formVisible" :close-on-click-modal="false" :close-on-press-escape="false" width="40%" @close="addFormclose">
        <el-form :model="addForm" ref="ruleForm" :rules="rules" class="diolog_adapt" style="width: 600px">
          <el-form-item label="账号性质:" label-width="130px" prop="account_type">
            <el-radio-group v-model="addForm.account_type" :disabled="editSubjects" @input="setTempOption">
              <el-radio :label="1">设备sn</el-radio>
              <el-radio :label="2">学习卡账号</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="账号或sn" label-width="130px" prop="account">
            <el-select v-model="addForm.account" filterable placeholder="请输入账号或sn" clearable :disabled="editSubjects">
              <el-option
                v-for="item in tempOptions"
                :key="item.id"
                :label="item.sn"
                :value="item.sn">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="责任教师:" label-width="130px" prop="sup_teacher">
            <el-select v-model="addForm.teacher" filterable placeholder="请选择责任督学师">
              <el-option
                v-for="item in teacherArr"
                :key="item.id"
                :label="item.username"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="formVisible = false" size="mini" round>取 消</el-button>
          <el-button v-if="editSubjects" type="primary" @click="editAccountLimit('ruleForm')" size="mini" round>确定
          </el-button>
          <el-button v-else type="primary" @click="addStudentControl('ruleForm')" size="mini" round>确定</el-button>
        </div>
      </el-dialog>

      <el-dialog title="编辑课时" :visible.sync="timeVisible" :close-on-click-modal="false" :close-on-press-escape="false" width="40%" @close="courseTimeClose">
        <el-form :model="courseTimeForm" ref="courseTimeForm" :rules="hourRules" class="diolog_adapt" style="width: 600px">
          <el-form-item label="督学总课时:" label-width="130px" prop="sup_all_time">
            <el-input-number v-model="courseTimeForm.sup_all_time" :precision="1" :step="0.5" :max="999" :min="0"></el-input-number>
          </el-form-item>
          <el-form-item label="伴学总课时:" label-width="130px" prop="acc_all_time">
            <el-input-number v-model="courseTimeForm.acc_all_time" :precision="1" :step="0.5" :max="999" :min="0"></el-input-number>
          </el-form-item>
          <el-form-item label="操作说明:" label-width="130px" prop="explain">
            <el-input type="textarea" v-model="courseTimeForm.explain"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="timeVisible = false" size="mini" round>取 消</el-button>
          <el-button type="primary" @click="editCourseHourControl('courseTimeForm')" size="mini" round>确定
          </el-button>
        </div>
      </el-dialog>
      <el-dialog title="课时操作日志" :visible.sync="timeLogVisible" :close-on-click-modal="false" :close-on-press-escape="false" width="60%" @close="closeTimeLog">
        <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
          <el-tab-pane label="督学课时" name="sup"></el-tab-pane>
          <el-tab-pane label="伴学课时" name="acc"></el-tab-pane>
        </el-tabs>
        <el-table stripe style="width: 100%" border fit highlight-current-row :data="hourLogData" :key="key">
          <el-table-column min-width="50" align="center" prop="id" label="ID"></el-table-column>
          <el-table-column min-width="120" align="center" prop="create_time" label="操作时间"></el-table-column>
          <el-table-column min-width="50" align="center" prop="current_all_time" label="当前总课时"></el-table-column>
          <el-table-column min-width="70" align="center" prop="current_residue_time" label="当前剩余课时"></el-table-column>
          <el-table-column min-width="50" align="center" prop="change" label="课时变化">
            <template slot-scope="scope">
              <span style="color: #67C23A" v-if="scope.row.change>0">+{{ scope.row.change }}</span>
              <span style="color: #F56C6C" v-else>-{{ scope.row.change }}</span>
            </template>
          </el-table-column>
          <el-table-column min-width="50" align="center" prop="operateName" label="操作账号"></el-table-column>
          <el-table-column min-width="150" align="center" prop="explain" label="操作说明"></el-table-column>
        </el-table>
      </el-dialog>

      <el-dialog title="学习任务" :visible.sync="taskVisible" :close-on-click-modal="false" :close-on-press-escape="false" width="60%">
        <el-tabs v-model="taskType" type="card" @tab-click="handleTaskClick">
          <el-tab-pane label="当前任务" name="current"></el-tab-pane>
          <el-tab-pane label="日任务" name="day"></el-tab-pane>
          <el-tab-pane label="周任务" name="week"></el-tab-pane>
          <el-tab-pane label="月任务" name="month"></el-tab-pane>
          <el-tab-pane label="所有任务" name="all"></el-tab-pane>
        </el-tabs>
        <el-table stripe style="width: 100%" border fit highlight-current-row :data="taskTableData" :key="key">
          <el-table-column min-width="50" align="center" prop="id" label="ID"></el-table-column>
          <el-table-column min-width="50" align="center" prop="username" label="姓名"></el-table-column>
          <el-table-column min-width="50" align="center" prop="gradeName" label="年级"></el-table-column>
          <el-table-column min-width="50" align="center" prop="subjectName" label="学科"></el-table-column>
          <el-table-column min-width="100" align="center" prop="date_type" label="任务类别">
            <template slot-scope="scope">
              <span v-if="scope.row.date_type===1">日任务</span>
              <span v-else-if="scope.row.date_type===2">周任务</span>
              <span v-else>月任务</span>
            </template>
          </el-table-column>
          <el-table-column min-width="100" align="center" prop="name" label="任务名称"></el-table-column>
          <el-table-column v-if="taskType==='current'" min-width="80" align="center" prop="username" label="当前情况">
            <template slot-scope="scope">
              <span v-if="scope.row.is_done===1" style="color: #67C23A">已完成</span>
              <span v-else style="color: #F56C6C">未完成</span>
            </template>
          </el-table-column>
          <el-table-column min-width="80" align="center"  label="整体情况">
            <template slot-scope="scope">
              <span>{{scope.row.done_num}}/{{scope.row.task_num}}</span>
            </template>
          </el-table-column>
          <el-table-column min-width="100" align="center"  label="任务有效期">
            <template slot-scope="scope">
              <div v-if="scope.row.date_type === 1 || scope.row.date_type === 2">
                <span>{{scope.row.expire_start_day}}</span>
                <span>{{scope.row.expire_end_day}}</span>
              </div>
              <div v-else>
                <span>{{scope.row.date_select}}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column min-width="100" align="center" prop="create_time" label="创建日期">
            <template slot-scope="scope">
              <span>{{scope.row.create_time | newDate}}</span>
            </template>
          </el-table-column>
          <el-table-column min-width="80" align="center" prop="admin_name" label="创建人"></el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-row>
                <el-button  size="mini" type="primary" @click="openDetailTask(scope.row.id)">查看详情</el-button>
              </el-row>
            </template>
          </el-table-column>
        </el-table>
      </el-dialog>
      <el-dialog title="任务详情" :visible.sync="taskDetailVisible" :close-on-click-modal="false" :close-on-press-escape="false" width="40%">
        <el-descriptions :column="2" border>
          <el-descriptions-item label="任务类别" :contentStyle="{'text-align': 'left'}">{{taskInfo.dateExplain}}</el-descriptions-item>
          <el-descriptions-item label="有效期">{{taskInfo.expireExplain}}</el-descriptions-item>
          <el-descriptions-item label="跳转方式">{{taskInfo.jumpExplain}}</el-descriptions-item>
          <el-descriptions-item label="提醒时间">{{taskInfo.remindExplain}}</el-descriptions-item>
          <el-descriptions-item label="责任老师">{{taskInfo.teacherName}}</el-descriptions-item>
          <el-descriptions-item label="任务名称">{{taskInfo.name}}</el-descriptions-item>
          <el-descriptions-item label="任务内容">{{taskInfo.remark}}</el-descriptions-item>
        </el-descriptions>
        <el-table stripe style="width: 100%" border fit highlight-current-row :data="taskDetailData" :key="key">
          <el-table-column min-width="50" align="center" prop="id" label="ID"></el-table-column>
          <el-table-column min-width="50" align="center" prop="username" label="姓名"></el-table-column>
          <el-table-column min-width="50" align="center" prop="gradeName" label="年级"></el-table-column>
          <el-table-column min-width="50" align="center" prop="subjectName" label="学科"></el-table-column>
          <el-table-column min-width="110" align="center" prop="lll" label="任务日期"></el-table-column>
          <el-table-column min-width="80" align="center" label="完成情况">
            <template slot-scope="scope">
              <span v-if="scope.row.is_done===1" style="color: #67C23A">已完成</span>
              <span v-else style="color: #F56C6C">未完成</span>
            </template>
          </el-table-column>
          <el-table-column min-width="80" align="center" prop="done_time" label="完成时间"></el-table-column>
        </el-table>
      </el-dialog>
      <el-dialog title="批量导入学员" :visible.sync="consumeFormVisible" :close-on-click-modal="false" :close-on-press-escape="false" width="40%" @close="consumeFormClose">
        <el-form :model="consumeForm"  ref="consumeForm" :rules="consumeRules" class="diolog_adapt" style="width: 600px" >
          <el-form-item label="导入文件:" label-width="130px" class="snElsx">
            <div class="">
              <el-input autocomplete="off" placeholder="请点击上传，上传xls或xlsx文件" v-model="consumeForm.file.name"></el-input>
              <upload-excel-component class="flex mrg-top" :before-upload="batchUpload" @submitXlsx="submitXlsx"
                                      :loading="!videoFlag">
                <span>{{videoFlag ? '' : goodsData + '%'}}</span>
              </upload-excel-component>
            </div>
          </el-form-item>
          <div v-if="batchShow">
            <el-form-item label="成功导入:" label-width="130px" style="margin-bottom:0">共{{ this.accountData.success}}条
            </el-form-item>
            <el-form-item label="导入失败:" label-width="130px" style="margin-bottom:0"> 共{{ this.accountData.err}}条
              {{ this.accountData.errorCol.length >= 1 ? `( 位于:第${this.accountData.errorCol.toString()}行 ), 只展示前10行` : ''}}
            </el-form-item>
            <el-form-item label="重复的账号:" label-width="130px" style="margin-bottom:0">共{{this.accountData.repeat.length}}条
              {{ this.accountData.repeat.length >= 1 ? `( 位于:第${this.accountData.repeat.toString()}行 ), 只展示前10行` : ''}}
            </el-form-item>
          </div>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary"  @click="consumeFormVisible = false"  size="mini" round>确定</el-button>
        </div>
      </el-dialog>

      <el-dialog title="SN码导出" :visible.sync="exportFormVisible" :close-on-click-modal="false" @close="exportFormClose" :close-on-press-escape="false" width="35%">
        <el-form :model="exportForm">
          <el-form-item label="导出类型:" label-width="130px">
            <el-select v-model="exportForm.type" placeholder="请选择">
              <el-option label="按归属导出"  :value="1"></el-option>
              <el-option label="按责任教师导出" :value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-if="exportForm.type===1" label="归属" label-width="130px">
            <el-select v-model="exportForm.agent" filterable  placeholder="请选择归属">
              <el-option
                v-for="item in agentArr"
                :key="item.id"
                :label="item.username"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-else label="责任教师" label-width="130px">
            <el-select v-model="exportForm.teacher" filterable placeholder="请选择责任督学师">
              <el-option
                v-for="item in teacherArr"
                :key="item.id"
                :label="item.username"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="exportFormVisible = false" size="mini" round>取 消</el-button>
          <el-button type="primary" @click="getDownloadStudent" size="mini" round>确 定</el-button>
        </div>
      </el-dialog>
      <div v-if="reportVisible" class="modal">
        <div class="modal-content">
          <span @click="reportVisible = false" class="close">&times;</span>
          <iframe :src="reportUrl" width="100%" height="100%" frameborder="0"></iframe>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import objectable from "@/utils/objectable.js";
import dynamicTable from "@/components/DynamicTable/index";
import deleteDialog from "@/components/deleteDialog/index";
import tableMini from '@/utils/tableMini.js'
import permission from "@/directive/permission";
import score from "./components/score.vue"
import {
  addStudent,
  batchAddStudent,
  batchDelStudent,
  batchDownStudent,
  delStudent,
  editCourseHour,
  editStudent,
  getSupAndAccTeacher, getTaskDetail,
  queryCourseHourLog,
  querySelfAccount,
  queryStudentControl,
  queryStudentTaskById,
} from "@/api/teacher";
import UploadExcelComponent from "@/components/UploadExcelSn/index.vue";
import {mapState} from "vuex";
import {Loading} from "element-ui";
import {getAgentAndSchool} from "@/api/equipment";
import {getGanKaoUrl, loginGanKaoH5} from "@/api/qid";

export default {

  mixins: [tableMini],
  components: {UploadExcelComponent, dynamicTable, deleteDialog, score},
  directives: {permission},
  data() {
    return {
      key: 1,
      colData: [], //动态控制table
      checkboxVal: ["ID", "账号", "QID", "归属", "姓名", "性别", "年级", "详细地址", "校区", "责任教师", "最后登录日期", "最后登录设备SN", "督学总课时", "督学余课时", "伴学总课时", "伴学余课时", "彩虹币"],
      searchTable: "",
      select: "", //搜索条件
      tableData: [],
      listQuery: {
        startSize: 1,
        pageSize: 10,
        userId: localStorage.getItem("ID"),
        roomId: this.$route.query.roomID
      },
      addForm: {
        account_type: 1,
        account: '',
        teacher: '',
      },
      formVisible: false,
      rules: {
        account: [{required: true, message: '请输入账号', trigger: 'blur'}],
        account_type: [{required: true, message: '请选择账号性质', trigger: 'change'}],
      },
      hourRules: {
        explain: [{required: true, message: '请输入操作说明', trigger: 'blur'}],
      },
      editSubjects: false,
      deleteDialogs: {show: false, deleteText: '', deleteId: 0},
      dialogVisible: false,
      teacherArr: [],
      timeVisible: false,
      timeLogVisible: false,
      courseTimeForm: {
        sup_all_time: 0,  //督学总课时
        acc_all_time: 0,  //伴学总课时
        explain: '',
        studentId: 0
      },
      logQuery: {studentId: 0, type: 1},
      hourLogData: [],
      activeName: 'sup',
      multipleSelection: [],
      scoreVisible: false,
      studentInfo: {},
      accountOptions: [],
      phoneOptions: [],
      tempOptions: [],
      taskVisible: false,
      taskArr: [],
      options:[{value: 1,label: '语文'},{value: 2, label: '数学'},{value:3,label: '英语'},{value: 4,label: '政治'}, {value: 5, label: '历史'},{value:6, label: '地理'},
        {value:7, label: '物理'}, {value: 8, label: '化学'}, {value: 9, label: '生物'}, {value: 10, label: '科学'}],
      appChargeOptions: [],
      sendOptions: [],
      consumeFormVisible: false,
      consumeForm: {
        platter: '',
        count: '',
        file: [],
        id: '',
        platter_id: '',
      },
      consumeRules: {
        file:  [{required: true, message: '请选择文件', trigger: 'blur'}]
      },
      videoFlag: true,
      batchShow:false,
      accountData: {},
      exportFormVisible: false,
      exportForm: {type: 1, teacher:'', agent:''},
      agentArr: [],
      taskType: 'current',
      taskTableData: [],
      studentIdForTask: 0,
      taskDetailVisible: false,
      taskDetailData: [],
      taskInfo: [],
      reportUrl: '',
      reportVisible: false,
    }
  },
  created() {
    this.colData = objectable(this.checkboxVal, this.checkboxVal); //转为数组对象，好控制table
    this.getStudent()
    this.getSupAndAccTeacherControl()
    this.queryAgentAccount()
    this.getAgentAndSchool()
  },
  computed: {
    ...mapState({//获取上传滚动条
      goodsData: state => state.user.progress
    })
  },
  methods: {
    Refresh() {
      this.listQuery = {startSize: 1, pageSize: 10, userId: localStorage.getItem("ID")}
      this.getStudent()
    },
    getSupAndAccTeacherControl() {
      getSupAndAccTeacher({userId: localStorage.getItem("ID")}).then(res => {
        this.teacherArr = res.data
      }).catch(err => {
        this.teacherArr = []
      })
    },
    scoreClose() {
      this.scoreVisible = false
    },
    scoreShow(item) {
      this.scoreVisible = true
      this.studentInfo = item
    },
    //搜索
    idnameSearch() {
      if (!this.select) return this.$message.warning("请先选择查询条件");
      this.listQuery.startSize = 1
      this.listQuery.pageSize = 10
      switch (this.select) {
        case '1':
          this.listQuery.account = this.searchTable
          this.getStudent();
          break;
      }
    },
    openEdit(row) {
      this.formVisible = true
      this.editSubjects = true
      this.addForm = {
        account_type: row.account_type,
        account: row.account,
        teacher: row.teacher_id,
        id: row.id
      }
    },
    openHourEdit(row) {
      this.timeVisible = true
      this.courseTimeForm = {
        sup_all_time: row.sup_all_time,  //督学总课时
        acc_all_time: row.acc_all_time,  //伴学总课时
        explain: '',
        studentId: row.id
      }
    },
    openHourLog(row) {
      this.timeLogVisible = true
      this.logQuery = {studentId: row.id, type: 1}
      this.queryHourLogControl(1)
    },

    editAccountLimit(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          let editForm = JSON.parse(JSON.stringify(this.addForm))
          editForm.last_ip = sessionStorage.getItem("Ip")
          editForm.userId = localStorage.getItem("ID")
          editStudent(editForm).then(res => {
            this.$message.success(res.msg)
            this.getStudent()
            this.formVisible = false
            this.editSubjects = false
          }).catch(err => {
          })
        } else {
          return false;
        }
      });
    },
    addStudentControl(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          let addForm = JSON.parse(JSON.stringify(this.addForm))
          addForm.last_ip = sessionStorage.getItem("Ip")
          addForm.userId = localStorage.getItem("ID")
          addStudent(addForm).then(res => {
            this.$message.success(res.msg)
            this.getStudent()
            this.formVisible = false
          }).catch(err => {
          })
        } else {
          return false;
        }
      });
    },
    editCourseHourControl(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          let editForm = JSON.parse(JSON.stringify(this.courseTimeForm))
          editForm.last_ip = sessionStorage.getItem("Ip")
          editForm.userId = localStorage.getItem("ID")
          editCourseHour(editForm).then(res => {
            this.$message.success(res.msg)
            this.getStudent()
            this.timeVisible = false
          }).catch(err => {
          })
        } else {
          return false;
        }
      });
    },
    getStudent() {
      queryStudentControl(this.listQuery).then(res => {
        this.tableData = res.data
        this.total = res.total
      }).catch(err => {
        this.tableData = []
        this.total = 0
      })
    },
    queryHourLogControl(type) {
      this.logQuery.type = type
      queryCourseHourLog(this.logQuery).then(res => {
        this.hourLogData = res.data
      }).catch(err => {
        this.hourLogData = []
      })
    },
    queryStudentTask(type) {
      queryStudentTaskById({
        studentId: this.studentIdForTask,
        type: type
      }).then(res => {
        this.taskTableData = res.data
      }).catch(err => {
        console.log(err)
      })
    },
    delContent(id) {
      this.deleteDialogs.show = true
      this.deleteDialogs.deleteId = id
    },
    //删除按钮事件
    deleteEvents() {
      let params = {
        userId: localStorage.getItem("ID"),
        last_ip: sessionStorage.getItem("Ip"),
        id: this.deleteDialogs.deleteId,
      }
      delStudent(params).then(res => {
        if (res.code == 200) {
          this.$message.success(res.msg)
        } else {
          this.$message.error(res.msg)
        }
        this.getStudent()
      }).catch(err => {
        console.log("请求失败", err)
      })
    },
    //分页
    handleSizeChange(val) {
      this.listQuery.pageSize = val
      this.getStudent()
    },
    handleCurrentChange(val) {
      this.listQuery.startSize = val
      this.getStudent()
    },
    //表格排序事件
    tableSortCge(column) {
      let order = ''
      column.order == "descending" ? order = 'desc' : order = 'asc'
      let sort = [{field: column.prop, sort: order}]
      this.listQuery.sort = JSON.stringify(sort)
      this.getStudent()
    },
    //下拉动态table子组件
    alterCheckbok(key, conte) {
      this.key = key;
      this.colData.filter(i => {
        if (conte.indexOf(i.title) != -1) {
          i.istrue = false;
          this.$nextTick(() => {
            this.$refs.tableDataRef.doLayout();
          });
        } else {
          i.istrue = true;
          this.$nextTick(() => {
            this.$refs.tableDataRef.doLayout();
          });
        }
      });
    },
    //编辑添加表单关闭事件
    addFormclose() {
      this.editSubjects = false
      this.$nextTick(() => {
        this.addForm = {
          account_type: 1,
          account: '',
          teacher: '',
        }
      })
    },
    courseTimeClose() {
      this.timeVisible = false
      this.$nextTick(()=> {
        this.courseTimeForm = this.$options.data.call(this).courseTimeForm
      })
    },
    handleClick(tab, event) {
      if (tab.name === 'sup') {
        this.queryHourLogControl(1)
      } else {
        this.queryHourLogControl(2)
      }
    },
    handleTaskClick(tab, event) {
     this.queryStudentTask(tab.name)
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handelDelete() {
      if (this.multipleSelection.length === 0) {
        this.$message({
          message: '请至少选择一项进行操作',
          type: 'warning'
        });
        return;
      }
      this.$confirm('此操作将永久删除选中的数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 批量删除逻辑
        const ids = this.multipleSelection.map(item => item.id); // 假设每个对象都有id属性
        batchDelStudent({
          ids: ids,
          userId: localStorage.getItem("ID"),
        }).then(res => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.getStudent()
        })
      }).catch((err) => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    queryAgentAccount(){
      querySelfAccount({
        userId: localStorage.getItem("ID"),
      }).then(res => {
        this.accountOptions = res.data['sn']
        this.phoneOptions = res.data['phone']
        this.tempOptions = res.data['sn']
      })
    },
    setTempOption(e) {
      if (e === 1) {
        this.tempOptions = this.accountOptions
      }else {
        this.tempOptions = this.phoneOptions
      }
    },
    openTask(id) {
      this.taskVisible = true
      this.studentIdForTask = id
      this.queryStudentTask('current')
    },
    closeTimeLog() {
      this.activeName = 'sup'
    },
    consumeFormClose() {
      this.$nextTick(() => {
        this.consumeForm = this.$options.data.call(this).consumeForm
        this.videoFlag = true
        this.batchShow = false
      })
    },
    batchUpload(file) {
      this.consumeForm.file = file
    },
    submitXlsx(event) {
      var fd = new FormData()
      fd.append('file', this.consumeForm.file)
      fd.append('userId', localStorage.getItem("ID"))
      fd.append('last_ip', sessionStorage.getItem("Ip"))
      this.videoFlag = false
      batchAddStudent(fd).then(res => {
        this.accountData = res.data
        this.batchShow = true
        this.$message.success(res.msg)
        this.videoFlag = true
        this.getStudent()
      }).catch(err => {
        this.videoFlag = true
      })
    },
    handleDownload() {
      let tHeader = ["账号", "责任教师"];
      let filterVal = ["account", "teacher"];
      let list = [{ "account": 'QRS5c3300006', "teacher": '橘子'}]
      import("@/vendor/Export2Excel").then(excel => {
        const data = this.formatJson(filterVal, list);
        excel.export_json_to_excel({ header: tHeader, data, filename: '批量导入模板' });
      });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v =>
        filterVal.map(j => {
          if (j === "timestamp") {
            return parseTime(v[j]);
          } else {
            return v[j];
          }
        })
      );
    },
    getDownloadStudent() {
      let exportForm = JSON.parse(JSON.stringify(this.exportForm))
      exportForm.userId = localStorage.getItem("ID")
      let loadingInstance = Loading.service({ target: '.content2' })
      batchDownStudent(exportForm).then(res => {
        window.open('https://' + res.data.url)
        this.$nextTick(() => {
          loadingInstance.close();
        });
      }).catch(err => {
        this.$nextTick(() => {
          loadingInstance.close();
        });
        err.code == 400 ? this.$message.error(err.msg) : ''
      })
    },
    getAgentAndSchool() {
      getAgentAndSchool({userId: localStorage.getItem("ID")}).then(res => {
        this.agentArr = res.data
      }).catch(err => {
        this.agentArr = []
      })
    },
    exportFormClose() {
      this.exportForm = this.$options.data.call(this).exportForm
    },
    openDetailTask(id) {
      this.taskDetailVisible = true
      getTaskDetail({
        studentId: this.studentIdForTask,
        taskId: id
      }).then(res => {
        this.taskDetailData = res.data
        this.taskInfo = res.otherData
      }).catch(err => {
        console.log(err)
      })
    },
    goToGanKao(uid) {
      if (uid === 0 || uid.length <= 1) {
        this.$message.info("该学生未注册")
        return
      }
      loginGanKaoH5({
        uid: uid
      }).then(res => {
        this.reportUrl = res.data.url
        this.reportVisible = true
      })
      // this.reportUrl = `https://colorful2.gankao.com/p-account/statistics/student?gankaoUID=${uid}`;
      // this.reportVisible = true
    }
  }
}
</script>

<style scoped>
/* 添加一些基本的样式 */
.modal {
  position: fixed;
  z-index: 1050;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.4);
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-content {
  background-color: #fefefe;
  padding: 20px;
  border-radius: 5px;
  position: relative;
  width: 80%;
  height: 80%;
}

.close {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
}
</style>
